import json

from fdfs_client.client import Fdfs_client
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet


class UploadAvatarView(ModelViewSet):
    def post(self,request):
        c=Fdfs_client('/home/ubuntu/Desktop/tensqure/tensquare/tensquare/utils/fastdfs/client.conf')
        f=request.FILES.get('img')
        img=f.read()
        rec=c.upload_by_buffer(img)
        dir='http://192.168.65.128:8888/'


        return Response({
            'imgurl': dir+rec['Remote file_id']
        })
